package 十字转门;

/**
问题描述：
假如转门处于锁定状态LockedTurnstileState，当投币事件发生(coin()方法时，转门将转换到非锁定状态，并且执行解锁动作（Turnstile类的unLock()方法）。

假如转门处于非锁定状态UnLockedTurnstileState，当有人通过门(pass()方法)时，转门将转换到锁定状态，并且将执行锁定动作(Turnstile类的lock()方法）。

当转门处于锁定状态，当有人通过门时 ，执行警告动作 (Turnstile类的alarm()方法）

当转门已经处于非锁定状态,当投币事件发生,执行谢谢动作（Turnstile类的thankYou()方法）

请实现 LockedTurnstileState 及 UnLockedTurnstileState 类并提交



interface TurnstileState

{

    void coin();

    void pass();

}



请实现 LockedTurnstileState  和  UnLockedTurnstileState 类并提交

class LockedTurnstileState implements TurnstileState{



}



class UnLockedTurnstileState implements TurnstileState{



}


class Turnstile

{   private  TurnstileState lockedState;

    private  TurnstileState unlockedState;

    private TurnstileState state=lockedState;

    public Turnstile(){

        lockedState=new LockedTurnstileState(this);

        unlockedState=new UnLockedTurnstileState(this);

    }

    public TurnstileState getLockedState() {

        return lockedState;

    }



    public TurnstileState getUnlockedState() {

        return unlockedState;

    }



    public void setState(TurnstileState state){

        this.state=state;

    }



    public void coin(){

        state.coin();

    }

    public void pass(){

        state.pass();

    }

    public void unLock(){

        System.out.println("turnstile unlock");

    }

    public void lock(){

        System.out.println("turnstile lock");

    }

    public void alarm(){

        System.out.println("alarm");



    }

    public void thankYou(){

        System.out.println("think you");



    }

}



public class Main {

    public static void main(String[] args){

        Turnstile turnstile=new Turnstile();

        turnstile.setState(turnstile.getLockedState());

        turnstile.coin();

        turnstile.coin();

        turnstile.pass();

        turnstile.pass();

    }



}



    输入描述
            输入描述

输出描述
        turnstile unlock

        think you

        turnstile lock

        alarm

        提示
        实现 LockedTurnstileState  和  UnLockedTurnstileState 类并提交

        样例输入  复制  更多
        样例输出
        turnstile unlock
        think you
        turnstile lock
        alarm
        允许最长运行时间
        1000ms
        允许使用最大内存
        64MB
 **/

interface TurnstileState

{

    void coin();

    void pass();

}





class LockedTurnstileState implements TurnstileState{
    private Turnstile turnstile;
    public LockedTurnstileState(Turnstile turnstile){
        this.turnstile=turnstile;
    }

    @Override
    public void coin() {
        turnstile.setState(turnstile.getUnlockedState());
        turnstile.unLock();

    }

    @Override
    public void pass() {
        turnstile.alarm();
    }
}



class UnLockedTurnstileState implements TurnstileState{

    private Turnstile turnstile;
    public UnLockedTurnstileState(Turnstile turnstile){
        this.turnstile=turnstile;
    }
    @Override
    public void coin() {
        turnstile.thankYou();
    }

    @Override
    public void pass() {
        turnstile.setState(turnstile.getLockedState());
        turnstile.lock();
    }
}


class Turnstile

{   private  TurnstileState lockedState;

    private  TurnstileState unlockedState;

    private TurnstileState state = lockedState;

    public Turnstile(){

        lockedState=new LockedTurnstileState(this);

        unlockedState=new UnLockedTurnstileState(this);

    }

    public TurnstileState getLockedState() {

        return lockedState;

    }



    public TurnstileState getUnlockedState() {

        return unlockedState;

    }



    public void setState(TurnstileState state){

        this.state=state;

    }



    public void coin(){

        state.coin();

    }

    public void pass(){

        state.pass();

    }

    public void unLock(){

        System.out.println("turnstile unlock");

    }

    public void lock(){

        System.out.println("turnstile lock");

    }

    public void alarm(){

        System.out.println("alarm");



    }

    public void thankYou(){

        System.out.println("think you");



    }

}



public class Main {

    public static void main(String[] args){

        Turnstile turnstile=new Turnstile();

        turnstile.setState(turnstile.getLockedState());

        turnstile.coin();

        turnstile.coin();

        turnstile.pass();

        turnstile.pass();

    }



}
